package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CustomRule;
import com.ruoyi.system.service.ICustomRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 自定义规则管理Controller
 * 
 * @author ruoyi
 * @date 2025-03-22
 */
@RestController
@RequestMapping("/system/rule")
public class CustomRuleController extends BaseController
{
    @Autowired
    private ICustomRuleService customRuleService;

    /**
     * 查询自定义规则管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomRule customRule)
    {
        startPage();
        List<CustomRule> list = customRuleService.selectCustomRuleList(customRule);
        return getDataTable(list);
    }

    /**
     * 导出自定义规则管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:rule:export')")
    @Log(title = "自定义规则管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomRule customRule)
    {
        List<CustomRule> list = customRuleService.selectCustomRuleList(customRule);
        ExcelUtil<CustomRule> util = new ExcelUtil<CustomRule>(CustomRule.class);
        util.exportExcel(response, list, "自定义规则管理数据");
    }

    /**
     * 获取自定义规则管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rule:query')")
    @GetMapping(value = "/{customRuleId}")
    public AjaxResult getInfo(@PathVariable("customRuleId") Long customRuleId)
    {
        return success(customRuleService.selectCustomRuleByCustomRuleId(customRuleId));
    }

    /**
     * 新增自定义规则管理
     */
    @PreAuthorize("@ss.hasPermi('system:rule:add')")
    @Log(title = "自定义规则管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomRule customRule)
    {
        return toAjax(customRuleService.insertCustomRule(customRule));
    }

    /**
     * 修改自定义规则管理
     */
    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @Log(title = "自定义规则管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomRule customRule)
    {
        return toAjax(customRuleService.updateCustomRule(customRule));
    }

    /**
     * 删除自定义规则管理
     */
    @PreAuthorize("@ss.hasPermi('system:rule:remove')")
    @Log(title = "自定义规则管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customRuleIds}")
    public AjaxResult remove(@PathVariable Long[] customRuleIds)
    {
        return toAjax(customRuleService.deleteCustomRuleByCustomRuleIds(customRuleIds));
    }
}
